<%-- 
    Document   : formAjoutCreneau4
    Created on : 5 avr. 2013, 18:14:59
    Author     : ali
--%>

<%@page import="EDT.obj.Salle"%>
<%@page import="EDT.obj.Intervenant"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                
        <title>Ajouter Un Creneau </title>
            <link rel="stylesheet" href="Accueil.css" />
            <link rel="SHORTCUT ICON" href="./edt.jpg" />
            		
   
    </head>

    <body>    
        
    <section>
        
<%        
        String form ="";
                             
        String pp = request.getParameter("promo");
        
        int idp = Integer.parseInt(pp);
       
        String key = (String) session.getAttribute("key");
        
        int idec =  Integer.parseInt(request.getParameter("ec")); 
        
        ArrayList<Intervenant> interv = new ArrayList<Intervenant>();
        
        ArrayList<Salle> salle = new ArrayList<Salle>();
         
       
        
        String jour= request.getParameter("dateHeure");
        int debut = Integer.parseInt(request.getParameter("alt_example_1_alt").replace(":", ""));
        int durer = Integer.parseInt(request.getParameter("durer"));
        int fin =debut+((durer / 60)*100)+(durer % 60);
        
        //out.println(idec+" -- "+jour+" --- "+debut+" --- "+fin);
        String type = request.getParameter("type");
        if(type.equals("cm")) type ="amphi";
        interv = EDT.api.API.getIntervDiso(key,idec,jour,debut,fin,idp);
        salle = EDT.api.API.getSalleDispo(key,type,jour,debut,fin);
        
        //salle = EDT.api.API.getSalle();
        //interv = EDT.api.API.getIntervenant(key,idec);
        
        form +="<form method='POST' action='AjoutCreneauAct.do' target='section'>\n";
        form += "<div class='commentaire'>\n";
        form += "<fieldset>";
               
        form += "<legend>    Choisissez un intervenant et une salle :   </legend>";
        
        form += "<input type='hidden' name='key' value='"+key+"'/>";
        
        form += "<input type='hidden' id ='idpromo' name='promo' value='"+idp+"'/>";
 
        form += "<input type='hidden' name='type' value='"+request.getParameter("type")+"'/>";
        
        form += "<input type='hidden' name='gp' value='"+request.getParameter("gp")+"'/>";
        
        form += "<input type='hidden' name='ec' value='"+request.getParameter("ec")+"'/>";
        
        form += "<input type='hidden' name='nbrCr' value='"+request.getParameter("nbrCr")+"'/>";
        
         form += "<input type='hidden' name='visible' value='"+request.getParameter("visible")+"'/>";
         
         form += "<input type='hidden' name='nbrPeriode' value='"+request.getParameter("nbrPeriode")+"'/>";
        
        form += "Intervenant : <select name='interv'>";
        for (Intervenant i : interv)
        form += "    <option value='"+i.getId()+"'>"+i.getPrenom()+" "+i.getNom()+"</option>";
        form += "</select><br/><br/>";
       
        
        form += "Salle : <select name='salle'>";
        for (Salle i : salle)
        form += "    <option value='"+i.getId()+"'>"+i.getNom()+"</option>";
        form += "</select><br/><br/>";
        
        form += "<input type='hidden' name='jour' value='"+jour+"'/>";
        form += "<input type='hidden' name='debut' value='"+debut+"'/>";
        form += "<input type='hidden' name='fin' value='"+fin+"'/>";
       
      
        
        if (salle.size() == 0 || interv.size() == 0){           
        form += "<input type='submit' value='valider' disabled/><br/><br/>";
        if(salle.size() == 0)
        form += "<label style='color:red;'>Dsl il n'y a pas  de salle disponible</label><br/>";
        if (interv.size() == 0)
        form += "<label style='color:red;'>Dsl il n'y a pas d'intervenant disponible</label><br/>";
        }else{
            form += "<input type='submit' value='valider'/><br/>";
        }
        
        out.println(form);
                
%>
        
     
    <html:errors/> 
    



    </fieldset>
    
        
    </div>

    </form>
  
</section>

    
    </body>
</html>
